<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
  </head>
  <style>
    #app {
      text-align: center;
    }

    img {
      width: 500px;
      height: 300px;
      object-fit: cover;
    }

    button {
      vertical-align: top;
      margin-top: 140px;
    }
  </style>

  <body>
    <!-- 
        1:默认显示第一张图片
            src的值  :src=第一张图片
        2:下一张
        3:上一张            
     -->
    <div id="app">
      <button @click="prev">上一张</button>
      <img :src="arr[currIndex]" alt="" />
      <button @click="next">下一张</button>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <script>
      new Vue({
        el: '#app',
        data: {
          currIndex: 0,
          arr: [
            'http://ossweb-img.qq.com/images/lol/web201310/skin/big145000.jpg',
            'http://ossweb-img.qq.com/images/lol/web201310/skin/big145001.jpg',
            'http://ossweb-img.qq.com/images/lol/web201310/skin/big145014.jpg',
            'http://ossweb-img.qq.com/images/lol/web201310/skin/big145015.jpg',
            'http://ossweb-img.qq.com/images/lol/web201310/skin/big145016.jpg',
            'http://ossweb-img.qq.com/images/lol/web201310/skin/big145017.jpg'
          ]
        },
        methods: {
          next () {
            this.currIndex++
            if (this.currIndex >= this.arr.length) {
              this.currIndex = 0
            }
          },
          prev () {
            this.currIndex--
            if (this.currIndex < 0) {
              this.currIndex = this.arr.length - 1
            }
          }
        }
      })
    </script>
  </body>
</html>
